package com.source.multithread.reentrantLo;

/**
 * @Author wengqy
 * @Date 2020/12/25
 */
public class ReentrantLockDemo {
    public static void main(String[] args) throws Exception {
                Phone phone = new Phone();
        // T1 线程在外层获取锁时，也会自动获取里面的锁
                new Thread(()->{
                    phone.sendSMS();
                    System.out.println("当前的线程为："+Thread.currentThread().getName()+">>>>>>>>>>>>>>"+Thread.currentThread() );
                },"T1").start();
                new Thread(()->{
                    phone.sendSMS();
                },"T2").start();


              /*  new Thread(()->{
                    phone.sendEmail();
                },"T1").start();
                new Thread(()->{
                    phone.sendEmail();
                },"T2").start();*/
   }
}


        class Phone{
            public synchronized void sendSMS(){
                System.out.println(Thread.currentThread().getName()+" sendSMS");
                sendEmail();
            }
            public synchronized void sendEmail(){
                System.out.println(Thread.currentThread().getName()+" sendEmail");
            }
        }


